package com.creatation.singleton;

public class DrRing {
    private String name;
    private Float price;
//    volatile 防止指令重排
//    懒汉、饿汉
    private volatile static DrRing instance;



//    @Override
//    public String toString() {
//        return "DrRing{" +
//                "name='" + name + '\'' +
//                ", price=" + price +
//                '}';
//    }
// 构造器私有，外部不能实例化
    private DrRing() {
        System.out.println("创建了DrRing");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Float getPrice() {
        return price;
    }

    public void setPrice(Float price) {
        this.price = price;
    }
//    设计一个方法去产生DrRing示例对象
//    双重检查锁+内存可见性   保证唯一性(双重检测for循环)
    public static DrRing getDrRing(){
        if (instance ==null){
            synchronized (DrRing.class){
                if (instance==null){
                    DrRing drRing = new DrRing();
                    instance = drRing;
                }
            }
        }
        return instance;
    }
}
